/*
    simplecookbook  -  simplecookbook.SimpleCookBookSingleton.java
                             -------------------
    begin                : 08/10/2008
    copyright            : (C) 2008 by cristovao
    email                : cristovao.wollieson@gmail.com
 ***************************************************************************/

/*
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   General Public License for more details.                              *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
 *   MA  02111-1307 USA                                                    *
 ***************************************************************************/

/**
 * Pacote principal da aplicacao cookbook
 */
package org.ybacoby.simplecookbook;

import org.ybacoby.simplecookbook.database.DataBase;
import org.ybacoby.simplecookbook.database.IDataBase;
import org.ybacoby.simplecookbook.database.SQLliteLocalHostDatabaseConnection;
import org.ybacoby.simplecookbook.exception.SimpleCookBookException;
import org.ybacoby.simplecookbook.impressao.GerarLivro;
import org.ybacoby.simplecookbook.impressao.IPrintBook;
import org.ybacoby.simplecookbook.ingredientes.ManterIngredientes;
import org.ybacoby.simplecookbook.ingredientes.RepositorioIngredientesSQLiteDataBase;
import org.ybacoby.simplecookbook.receitas.ManterReceitas;
import org.ybacoby.simplecookbook.receitas.RepositorioReceitasSQLiteDataBase;
import org.ybacoby.simplecookbook.utils.ISistemaDefinicoes;
import org.ybacoby.simplecookbook.utils.SistemaDefinicoes;

/**
 * Classe singleton, no caso classe que inicializa todos
 * os recursos do programa para facilidade de uso
 * 
 * @author cristovao
 *
 */
public class SimpleCookBookSingleton {

	/**
	 * Garantia de uma unica instancia
	 */
	private static SimpleCookBookSingleton cookBook = null;
	
	/**
	 * Para usar os comandos basicos do banco de dados
	 */
	private IDataBase database;
	
	/**
	 * Todas as definicoes usadas pelo sistema
	 */
	private ISistemaDefinicoes definicoes;
	
	/**
	 * Responsavel por imprimir o livro
	 */
	private IPrintBook print;
	
	/**
	 * Para controle de ingredientes no sistema
	 */
	private ManterIngredientes ingredientes;
	
	/**
	 * Para controle de receitas no sistema
	 */
	private ManterReceitas receitas;
	
	/**
	 * Constructor
	 * 
	 * @throws SimpleCookBookException Caso ocorra algum erro de inicializacao
	 */
	private SimpleCookBookSingleton() throws SimpleCookBookException {
		this.definicoes = new SistemaDefinicoes();
		this.database = new DataBase(new SQLliteLocalHostDatabaseConnection(this.definicoes.carregarDefinicao().getBancoDeDados()));
		this.ingredientes = new ManterIngredientes(new RepositorioIngredientesSQLiteDataBase(this.database));
		this.receitas = new ManterReceitas(new RepositorioReceitasSQLiteDataBase(this.database));
		this.print = new GerarLivro();
	}
	
	/**
	 * Serve para retornar uma unica instancia de todo o projeto
	 * 
	 * @return A instancia do projeto
	 * @throws SimpleCookBookException Caso nao possa ser iniciados os recursos
	 */
	public static SimpleCookBookSingleton getCookBookSingleton() throws SimpleCookBookException {
		
		// Instanciando caso ainda nao tenha sido instanciado
		if (cookBook == null) cookBook = new SimpleCookBookSingleton();
		
		// Retornando a instancia
		return cookBook;
	}

	/**
	 * @return the database
	 */
	public IDataBase getDatabase() {
		return database;
	}

	/**
	 * @return the ingredientes
	 */
	public ManterIngredientes getIngredientes() {
		return ingredientes;
	}

	/**
	 * @return the receitas
	 */
	public ManterReceitas getReceitas() {
		return receitas;
	}

	/**
	 * @return the print
	 */
	public IPrintBook getPrint() {
		return print;
	}

	/**
	 * @return the definicoes
	 */
	public ISistemaDefinicoes getDefinicoes() {
		return definicoes;
	}
}
